package com.cai.controller;

import com.cai.common.result.ResultVO;
import com.cai.entity.DTO.UserLoginParams;
import com.cai.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

/**
 * @Title: UserController
 * @Author RuoLi
 * @Package com.cai.controller
 * @Date 2024/1/12 9:19
 * @description: 用户控制
 */
@RestController
@Api("用户管理")
public class UserController {
    @Autowired
    private UserService userService;
    @PreAuthorize("hasAnyAuthority('/admin')")
    @GetMapping("/admin")
    @ApiOperation("管理员权限")
    public String admin() {
        return "admin";
    }
    @PreAuthorize("hasAnyAuthority('/user')")
    @GetMapping("/user")
    @ApiOperation("用户权限")
    public String user() {
        return "user";
    }
    @PostMapping("/login")
    @ApiOperation("退出登录")
    public ResultVO login(@RequestBody UserLoginParams params, @ApiIgnore HttpServletRequest request) {
        return userService.login(params,request);
    }
    @PostMapping("/logout")
    @ApiOperation("退出登录")
    public void logout() {

    }
}
